Rust Serde.html


* created: 2026-01-16T10:39
* modified: 2026-05-29T16:27

title

Rust Ecosystem: Serde

description

A crate used to serialize and deserialize.

Rust Ecosystem: Serde

Serde is composed of:

The Serde data model

A simplified form of the Rust type system; it contains primitives like bool, u8, u16, .. and char, but also string, byte array, option, unit and so on.

Serde requires the implementation of Serialize (describing how to emit data) and Deserialize (describing how to construct type from incoming data).

On the other side, the Serializer is responsible for converting the Serde data model to the bytes of the serialize protocol (e.g. JSON). The Deserializer maps the data of any given protocol to the Serde data model. When the Deserializer encounters a bool for example, it calls the visit-bool method, which ends up calling the corresponding deserialize method on our Rust data type.

The Serde data model is therefore not an intermediate type, which both sides can convert into, but more like a map telling you which functions to call if you want to construct your data type. The benefit being that we don't have to allocate memory for our in-between type, instead constructing the desired type directly.

Data is not converted into an intermediate "data model type"; it expresses itself in terms of the Serde data model.